//
//  main.m
//  Runtime归档解档
//
//  Created by rimi on 16/5/30.
//  Copyright © 2016年 薛涛. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "APPerson.h"
#import <objc/runtime.h>

void demo1();
void (*setter)(id,SEL,BOOL);

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        demo1();
        
        NSString *string = [NSString string];
        /**获取string中cmopare：方法地址*/
        setter = (void(*)(id,SEL,BOOL))[string methodForSelector:@selector(compare:)];
    }
    return 0;
}
/**解档归档*/
void demo1(){
    APPerson *person = [[APPerson alloc] init];
    person.name = @"zhangsan";
    person.crad = @"513822198892301200";
    person.birthday = @"19889230";
    person.age = 24;
    person.iphone = @"15342357930";
    person.adress = @"中国四川成都";
    person.heigth = 1.73;
    person.weight = 140;
    NSLog(@"%@",NSHomeDirectory());
    //设置路径
    NSString *path = [NSHomeDirectory()
                      stringByAppendingPathComponent:@"person.archiver"];
    //归档
    BOOL success = [NSKeyedArchiver archiveRootObject:person toFile:path];
    if (success) {
        NSLog(@"储存成功");
    }
    //解档
    APPerson *per = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
    NSLog(@"%@",per);
    
}